package cn.openea.perpartner.componet.web.service.importandexport;

import cn.openea.perpartner.common.core.exception.ServiceException;
import cn.openea.perpartner.componet.web.enums.ImportAndExportActions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 导入导出处理器
 * @createTime 2023年05月15日 17:06:00
 */
@Component
public class ImportAndExportHandler {

    @Autowired
    Map<String, ImportAndExportService> services = new ConcurrentHashMap<>();

    public ImportAndExportService getService(String code) {
        ImportAndExportActions actions = ImportAndExportActions.getByCode(code);
        if (actions == null) {
            throw new ServiceException("类型不存在!");
        }
        return getService(actions);
    }

    public ImportAndExportService getService(ImportAndExportActions actions) {
        ImportAndExportService importAndExportService = services.get(actions.getCode());
        if (importAndExportService == null) {
            throw new ServiceException("数据异常!");
        }
        return importAndExportService;
    }

}
